﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GUILib;
using MetaTracker.Model;
using System.Diagnostics;

namespace MetaTracker.ViewModel
{
    internal class TrackerBaseViewModel : ViewModelBase
    {
        #region Data and Properties

        protected TrackerModel tracker;

        public string UserName
        {
            get
            {
                return tracker.UserName;
            }
            set
            {
                tracker.UserName = value;
                NotifyPropertyChanged("UserName");
            }
        }
        public bool IsLoggedOn 
        {
            get
            {
                return tracker.IsLoggedOn;
            }
        }
        public string LoginMessage
        {
            get
            {
                return tracker.LoginMessage;
            }
        }
        public bool UserHasExercise
        {
            get
            {
                return tracker.UserHasExercise;
            }
        }
        public bool UserHasFood
        {
            get
            {
                return tracker.UserHasFood;
            }
        }
        public bool UserHasWeight
        {
            get
            {
                return tracker.UserHasWeight;
            }
        }

        public bool UserHasStatistics
        {
            get
            {
                return tracker.UserHasStatistics;
            }
        }

        #endregion //Data and Properties



        #region Constructor

        public TrackerBaseViewModel()
        {
            if (TrackerModel.SingletonInstance == null)
            {
                tracker = new TrackerModel();
            }
            else
            {
                tracker = TrackerModel.SingletonInstance;
            }

            tracker.LoginStateChanged += new TrackerModel.UpdateBindingsEventHandler(UpdateProperties);
            tracker.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(tracker_PropertyChanged);
            
        }

        void tracker_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            NotifyPropertyChanged(e.PropertyName);
        }

        void UpdateProperties(object sender, EventArgs e)
        {
            //NotifyPropertyChanged("UserHasWeight");
            //NotifyPropertyChanged("UserHasExerciset");
            //NotifyPropertyChanged("UserHasFood");
            //NotifyPropertyChanged("IsLoggedOn");
            //NotifyPropertyChanged("LoginMessage");
            //NotifyPropertyChanged("UserName");
        }

        #endregion //Constructor
    }
}
